<template>
  <section class="component case-return-query">
    <data-form :model="dataForm" :page="pageService" @handleResetForm="handleResetForm" @onSearch="refreshData">
      <template slot="inputs">
        <el-form-item label="订单号" prop="caseNumber">
          <el-input v-model="dataForm.caseNumber" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="批次号" prop="batchNumber">
          <el-input v-model="dataForm.batchNumber" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="委托方" prop="principalId">
          <el-select v-model="dataForm.principalId" placeholder="请选择" clearable>
            <el-option v-for="{index,name,id} in principalList.content" :key="index" :label="name" :value="id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="dataForm.personalName" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="dataForm.idCard" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="放款日期" prop="loanDate">
          <el-date-picker type="daterange" :editable="false" v-model="dataForm.loanDate" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model="dataForm.mobileNo" maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="业务团队" prop="partnerName">
          <el-input v-model="dataForm.partnerName" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="贷款银行" prop="bankName">
          <el-input v-model="dataForm.bankName" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="案件类型" prop="caseType">
          <el-select v-model="dataForm.caseType" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('CaseType')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="触发动作" prop="triggerAction">
          <el-select v-model="dataForm.triggerAction" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('TriggerAction')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="催收员/受托方" prop="name">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
        <el-form-item label="流转时间" prop="caseTurnTime">
          <el-date-picker type="datetimerange" :editable="false" v-model="dataForm.caseTurnTime" placeholder="选择日期时间" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="操作员" prop="operatorRealName">
          <el-input v-model="dataForm.operatorRealName" maxlength="20"></el-input>
        </el-form-item>
      </template>
    </data-form>
    <data-box :data="dataSet" @onPageChange="refreshData" :page="pageService">
      <template slot="columns">
        <el-table-column prop="caseNumber" label="订单编号" :min-width="$helper.getColumnWidth(6)">
          <template slot-scope="scope">
            <el-button type="text" @click="openExecutionPage(scope.row)">{{scope.row.caseNumber}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="batchNumber" label="批次号" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="principalName" label="委托方" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="loanDate" label="放款日期" :formatter="(row) => $filter.dateFormat(row.loanDate)" :min-width="$helper.getColumnWidth(6)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="partnerName" label="业务团队" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="bankName" label="贷款银行" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="caseType" label="案件类型" :formatter="(row) => $filter.dictConvert(row.caseType,'CaseType')" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="triggerAction" label="触发动作" :formatter="(row) => $filter.dictConvert(row.triggerAction,'TriggerAction')" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="caseTurnTime" label="流转时间" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip :formatter="(row) => $filter.dateTimeFormat(row.caseTurnTime)">
        </el-table-column>
        <el-table-column prop="name" label="催收员/受托方" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="operatorRealName" label="操作员" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
      </template>
    </data-box>
  </section>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import DataBox from '~/components/common/data-box.vue'
import DataForm from '~/components/common/data-form.vue'
import { PageService } from '~/utils/page.service'
import { Dependencies, Layout } from "~/core/decorator";
import { MENU_CHANNEL } from '../../config/enum.config';
import { State } from "vuex-class";
import { TurnRecordService } from '~/services/domain-service/turn-record.service'

@Layout("workspace")
@Component({
  components: {
    DataBox,
    DataForm
  }
})
export default class CaseReturnQuery extends Vue {
  @Dependencies(PageService)
  private pageService: PageService;
  @Dependencies(TurnRecordService)
  private turnRecordService: TurnRecordService;
  @State private principalList: any;


  private dataForm: any = {
    caseNumber: '',
    batchNumber: '',
    principalId: '',
    personalName: '',
    idCard: '',
    loanDate: [],
    mobileNo: '',
    partnerName: '',
    bankName: '',
    caseType: '',
    triggerAction: '',
    caseTurnTime: [],
    name: '',
    operatorRealName: ''
  }
  private dataSet: any = []

  private handleResetForm() { }

  private refreshData() {
    const params = { ...this.dataForm }
    params.caseTurnTimeStart = this.dataForm.caseTurnTime && this.dataForm.caseTurnTime.length ? this.$filter.dateTimeFormat(this.dataForm.caseTurnTime[0]) : ''
    params.caseTurnTimeEnd = this.dataForm.caseTurnTime && this.dataForm.caseTurnTime.length ? this.$filter.dateTimeFormat(this.dataForm.caseTurnTime[1]) : ''
    params.loanDateStart = this.$filter.dateRanageFormat(this.dataForm.loanDate).start
    params.loanDateEnd = this.$filter.dateRanageFormat(this.dataForm.loanDate).end
    delete params.caseTurnTime
    delete params.loanDate

    this.turnRecordService.findAllTurnRecord(params, this.pageService).subscribe(data => {
      this.dataSet = data
    })
  }

  private openExecutionPage(row) {
    this.$router.openCaseDetail(row.caseId, {
      menuChannel: MENU_CHANNEL.Case_return_query,
      hiddenCaseList: true,
      hiddenAction: true
    })
  }
  private created() {
    this.refreshData()
  }
}
</script>
<style lang="less">
</style>